package com.mxpio.erp.sales.policy.impl;


import com.mxpio.erp.common.enums.NoticeStatusEnums;
import com.mxpio.erp.common.enums.OrderEnums;
import com.mxpio.erp.common.enums.OrderStatusEnums;
import com.mxpio.erp.common.jpa.model.Order;
import com.mxpio.erp.common.order.policy.AbstractBizOrderPolicy;
import com.mxpio.erp.common.order.policy.OrderContext;
import com.mxpio.erp.common.sales.entity.RejectBill;
import com.mxpio.erp.common.vo.OrderExcuteLineVo;
import com.mxpioframework.jpa.JpaUtil;

import java.util.Date;
import java.util.List;

/**
 * 销售订单执行策略
 * @author fangsong
 *
 */
public class DefaultRejectPolicy extends AbstractBizOrderPolicy {

	private List<OrderExcuteLineVo> orderExcuteVos;

	public DefaultRejectPolicy(List<OrderExcuteLineVo> orderExcuteVos) {
		this.orderExcuteVos = orderExcuteVos;
	}

	@Override
	public void execute(OrderContext context) {
	}

	@Override
	public OrderContext config(OrderContext context) {
		context.setOrderExcuteVos(orderExcuteVos);
		context.setNoticeClass(RejectBill.class);
		context.setAccessType(OrderEnums.AccessType.IN.getCode());
		context.setPickingType(NoticeStatusEnums.NoticeType.SO_IN.getCode());
		return context;
	}

	@Override
	public boolean beforeExecute(OrderContext context) {
		return true;
	}

	@Override
	public void afterExecute(OrderContext context) {
		//更新状态
		Order order = context.getEntity();
		if(OrderStatusEnums.OrderStatus.ORDERED.getStatusCode().equals(order.getOrderStatus())) {
			order.setOrderStatus(OrderStatusEnums.OrderStatus.PROCESSING.getStatusCode());
			order.setExecuteTime(new Date());
			JpaUtil.update(order);
		}
	}

}
